<?php

namespace app\admin\model;

use think\Model;


class Approach extends Model
{

    

    

    // 表名
    protected $name = 'approach';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'inspect_time_text',
        'tmp_inspect_time_text',
        'create_time_text',
        'update_time_text',
        // 'project_status_text',
        'project_time_text',
        'tmp_project_time_text',
    ];
    

    // public function getProjectStatusTextAttr($value, $data)
    // {
    //     return $value ? $value : (isset(config('app.project_status')[$data['project_status']]) ? config('app.project_status')[$data['project_status']] : '');
    // }
    public function getProjectTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['project_time']) ? $data['project_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }
    public function getTmpProjectTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['tmp_project_time']) ? $data['tmp_project_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }

    public function getInspectTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['inspect_time']) ? $data['inspect_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getTmpInspectTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['tmp_inspect_time']) ? $data['tmp_inspect_time'] : '');
        return is_numeric($value) ? date("Y-m-d", $value) : $value;
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }
    protected function setProjectTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }
    protected function setTmpProjectTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    protected function setInspectTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setTmpInspectTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

}
